﻿
namespace XmlStudio.DataLayer {
    /// <summary>
    /// Helper class for XSD elements.
    /// </summary>
    public static class XsdElementParser {
        /// <summary>
        /// Gets <see cref="XsdElement"/> according to the parameter.
        /// </summary>
        /// <param name="name">Name of the element.</param>
        /// <returns><see cref="XsdElement"/>.</returns>
        public static XsdElement GetElementType(string name) {
            switch(name.ToLower()) {
                case "all":
                    return XsdElement.All;
                case "annotation":
                    return XsdElement.Annotation;
                case "any":
                    return XsdElement.Any;
                case "anyattribute":
                    return XsdElement.AnyAttribute;
                case "appinfo":
                    return XsdElement.AppInfo;
                case "attribute":
                    return XsdElement.Attribute;
                case "attributegroup":
                    return XsdElement.AttributeGroup;
                case "choice":
                    return XsdElement.Choice;
                case "complexcontent":
                    return XsdElement.ComplexContent;
                case "complextype":
                    return XsdElement.ComplexType;
                case "documentation":
                    return XsdElement.Documentation;
                case "element":
                    return XsdElement.Element;
                case "extension":
                    return XsdElement.Extension;
                case "field":
                    return XsdElement.Field;
                case "group":
                    return XsdElement.Group;
                case "import":
                    return XsdElement.Import;
                case "include":
                    return XsdElement.Include;
                case "key":
                    return XsdElement.Key;
                case "keyref":
                    return XsdElement.KeyRef;
                case "list":
                    return XsdElement.List;
                case "notation":
                    return XsdElement.Notation;
                case "redefine":
                    return XsdElement.Redefine;
                case "restriction":
                    return XsdElement.Restriction;
                case "schema":
                    return XsdElement.Schema;
                case "selector":
                    return XsdElement.Selector;
                case "sequence":
                    return XsdElement.Sequence;
                case "simplecontent":
                    return XsdElement.SimpleContent;
                case "simpletype":
                    return XsdElement.SimpleType;
                case "union":
                    return XsdElement.Union;
                case "unique":
                    return XsdElement.Unique;
                case "enumeration":
                    return XsdElement.Enumeration;
                case "fractiondigits":
                    return XsdElement.FractionDigits;
                case "length":
                    return XsdElement.Length;
                case "maxexclusive":
                    return XsdElement.MaxExclusive;
                case "maxinclusive":
                    return XsdElement.MaxInclusive;
                case "maxlength":
                    return XsdElement.MaxLength;
                case "minexclusive":
                    return XsdElement.MinExclusive;
                case "mininclusive":
                    return XsdElement.MinInclusive;
                case "minlength":
                    return XsdElement.MinLength;
                case "pattern":
                    return XsdElement.Pattern;
                case "totaldigits":
                    return XsdElement.TotalDigits;
                case "whitespace":
                    return XsdElement.WhiteSpace;
                default:
                    return XsdElement.AnyWellFormedXml;
            }
        }

        /// <summary>
        /// Gets element's name from the <see cref="XsdElement"/>.
        /// </summary>
        /// <param name="elementType">Element type.</param>
        /// <returns>Element name.</returns>
        public static string GetElementName(XsdElement elementType) {
            switch(elementType) {
                case XsdElement.All:
                    return "all";
                case XsdElement.Annotation:
                    return "annotation";
                case XsdElement.Any:
                    return "any";
                case XsdElement.AnyAttribute:
                    return "anyAttribute";
                case XsdElement.AppInfo:
                    return "appInfo";
                case XsdElement.Attribute:
                    return "attribute";
                case XsdElement.AttributeGroup:
                    return "attributeGroup";
                case XsdElement.Choice:
                    return "choice";
                case XsdElement.ComplexContent:
                    return "complexContent";
                case XsdElement.ComplexType:
                    return "complexType";
                case XsdElement.Documentation:
                    return "documentation";
                case XsdElement.Element:
                    return "element";
                case XsdElement.Extension:
                    return "extension";
                case XsdElement.Field:
                    return "field";
                case XsdElement.Group:
                    return "group";
                case XsdElement.Import:
                    return "import";
                case XsdElement.Include:
                    return "include";
                case XsdElement.Key:
                    return "key";
                case XsdElement.KeyRef:
                    return "keyRef";
                case XsdElement.List:
                    return "list";
                case XsdElement.Notation:
                    return "notation";
                case XsdElement.Redefine:
                    return "redefine";
                case XsdElement.Restriction:
                    return "restriction";
                case XsdElement.Schema:
                    return "schema";
                case XsdElement.Selector:
                    return "selector";
                case XsdElement.Sequence:
                    return "sequence";
                case XsdElement.SimpleContent:
                    return "simpleContent";
                case XsdElement.SimpleType:
                    return "simpleType";
                case XsdElement.Union:
                    return "union";
                case XsdElement.Unique:
                    return "unique";
                case XsdElement.Enumeration:
                    return "enumeration";
                case XsdElement.FractionDigits:
                    return "fractionDigits";
                case XsdElement.Length:
                    return "length";
                case XsdElement.MaxExclusive:
                    return "maxExclusive";
                case XsdElement.MaxInclusive:
                    return "maxInclusive";
                case XsdElement.MaxLength:
                    return "maxLength";
                case XsdElement.MinExclusive:
                    return "minExclusive";
                case XsdElement.MinInclusive:
                    return "minInclusive";
                case XsdElement.MinLength:
                    return "minLength";
                case XsdElement.Pattern:
                    return "pattern";
                case XsdElement.TotalDigits:
                    return "totalDigits";
                case XsdElement.WhiteSpace:
                    return "whiteSpace";
                default:
                    return "";
            }
        }
    }
}
